package com.hy.datart.util;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.zip.GZIPOutputStream;

public class Gzip {

    public static void compressFile(String sourcePath, String destinationFile) {
        try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(Files.newOutputStream(Paths.get(destinationFile)));
             InputStream inputStream = Files.newInputStream(Paths.get(sourcePath))) {
            byte[] buffer = new byte[1024];
            int read;
            while ((read = inputStream.read(buffer)) > 0) {
                gzipOutputStream.write(buffer, 0, read);
            }
            gzipOutputStream.finish();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}
